package aynu.oracle.video.service.Impl;

import aynu.oracle.video.dao.IVideoMapper;
import aynu.oracle.video.pojo.Author;
import aynu.oracle.video.pojo.Category;
import aynu.oracle.video.pojo.Video;
import aynu.oracle.video.service.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class VideoServiceImpl implements IVideoService {

    @Resource
    private IVideoMapper iVideoMapper;

    /**
     * 插入视频对象
     * @param video 视频对象
     * @return int
     */
    @Override
    public int insertVideo(Video video) {
        return iVideoMapper.insertVideo(video);
    }

    /**
     * 查询全部视频
     * @return list
     */
    @Override
    public List<Video> selectAllVideo(Integer index,Integer size) {
        return iVideoMapper.selectAllVideo(index,size);
    }

    /**
     * 按照ID查询，同时点击数+1
     * @param id 视频ID
     * @return video
     */
    @Override
    public Video selectVideoById(Integer id) {
        Video video = iVideoMapper.selectVideoById(id);
        if(video != null){
            // 点击数+1
            this.addNumberOfHits(id);
        }
        // 获取被点击的视频信息
        return video;
    }

    /**
     * 点击数+1
     * @param id 视频ID
     * @return int
     */
    @Override
    public int addNumberOfHits(Integer id) {
        return iVideoMapper.addNumberOfHits(id);
    }

    /**
     * 更新视频封面
     * @param id 视频ID
     * @param videoCoverPic 新的封面名称
     * @return int
     */
    @Override
    public int updateCoverPic(Integer id, String videoCoverPic) {
        return iVideoMapper.updateCoverPic(id,videoCoverPic);
    }

    @Override
    public int videoIsAudio(Integer[] ids) {
        return iVideoMapper.videoIsAudio(ids);
    }

    /**
     * 根据ID删除视频
     * @param ids 视频ID
     * @return int
     */
    @Override
    public int deleteVideoById(Integer[] ids) {
        return iVideoMapper.deleteVideoById(ids);
    }

    /**
     * 查询热门视频
     * @return list
     */
    @Override
    public List<Video> selectHotsVideo(Integer index,Integer size) {
        return iVideoMapper.selectHotsVideo(index,size);
    }

    /**
     * 按照类别分页查询
     * @param videoCategory 类别
     * @param index 起使索引
     * @param size 页面大小
     * @return list
     */
    @Override
    public List<Video> selectVideoByCategory(Integer videoCategory, Integer index, Integer size) {
        return iVideoMapper.selectVideoByCategory(videoCategory,index,size);
    }

    /**
     * 按照作者分页查询
     * @param videoAuthor 所属老师
     * @param index 起使索引
     * @param size 页面大小
     * @return list
     */
    @Override
    public List<Video> selectVideoByAuthor(Integer videoAuthor, Integer index, Integer size) {
        return iVideoMapper.selectVideoByAuthor(videoAuthor,index,size);
    }

    /**
     * 修改视频其他信息
     * @param video 视频对象
     * @return int
     */
    @Override
    public int updateVideoOtherInfo(Video video) {
        return iVideoMapper.updateVideoOtherInfo(video);
    }

    /**
     * 按照用户查询没有被审核的视频
     * @param videoUser 用户
     * @param index 起使索引
     * @param size 页面大小
     * @return list
     */
    @Override
    public List<Video> selectVideoByUserAndNotAudio(Integer videoUser, Integer index, Integer size) {
        return iVideoMapper.selectVideoByUserAndNotAudio(videoUser,index,size);
    }

    /**
     * 查询 老师 的类别
     * @return list 老师类别的集合
     */
    @Override
    public List<Author> selectVideoAuthor() {
        return iVideoMapper.selectVideoAuthor();
    }

    /**
     * 查询全部类别
     * @return 图片类别的集合
     */
    @Override
    public List<Category> selectVideoAllCategory() {
        return iVideoMapper.selectVideoAllCategory();
    }

    // 获取总数目
    @Override
    public int selectVideoCount() {
        return iVideoMapper.selectVideoCount();
    }

    // 根据用户ID获取总数目
    @Override
    public int selectVideoCountByVideoUser(Integer videoUser) {
        return iVideoMapper.selectVideoCountByVideoUser(videoUser);
    }

}
